package com.example.activity_service.controller;

import com.example.activity_service.Yuanchen.OrderService;
import com.example.activity_service.Yuanchen.UserService;
import com.example.activity_service.return_data.Mall_Data;
import com.example.activity_service.service.JPQueryService;
import com.example.activity_service.service.YssQueryService;
import com.example.activity_service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@ResponseBody
public class YssController {

    @Autowired
    JPQueryService jpQueryService;
    @Autowired
    YssQueryService service;

    @Autowired
    OrderService orderService;

    @Autowired
    UserService userService;


    @RequestMapping("/chajfsp")
    public List<Red_goods>searchjfsp(){
        List<Red_goods>list=jpQueryService.duica(0);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getTid());
        }

        return list;
    }
//查询未领取的优惠卷
    @RequestMapping("/chawei")
    public List<Red> chawei(){
        return  service.chawei();
    }

    //查未使用红包
    @RequestMapping("/chahb")
    public List<Red>searchhb(@RequestParam("users")int users)
    {
        List<Red>list=service.searchhb(users);
        return list;
    }

    //查已使用红包
    @RequestMapping("/chasyhb")
    public List<Red>searchsyhb(@RequestParam("users")int users)
    {
        List<Red>list=service.searchsyhb(users);
        return list;
    }


    //查过期红包
    @RequestMapping("/chagqhb")
    public List<Red>searchgqhb(
            @RequestParam("users")int users
    ){

        List<Red>list=service.searchgqhb(users);

        return list;
    }





    @RequestMapping("/xgsyhb")
    public int updatezt
            ( @RequestParam("id")int id,
              @RequestParam("status")int status
              )
    {
        service.updatezt(id, status);
        return 1;
    }



    @RequestMapping("/sggq")
    public int updategq(

            ){

service.updateguoqi();
return 1;

    }

    @RequestMapping("/chacss")
    public String cssss(
                  @RequestParam("user_id")String userid,
                  @RequestParam(value = "nm",required = false)String nm
                  ){
//        System.out.println(nm);
//        System.out.println(userid);
      String s=  service.addhuo(userid,nm);
    //  service.chacs(userid,nm);
        if (s=="1"){
            return "1";
        }
        return "0";
    }
    @RequestMapping("/addhuo")
    public String addhuo(@RequestParam("user_id")String id,@RequestParam("nm")String nm){

        String list=service.addhuo(id,nm);
        return "true";
    }
    @RequestMapping("/xiuhuo")
    public int xiuhuo(@RequestParam("user_id")String id,@RequestParam("nm")String nm){
        System.out.println(nm);

        service.xiuhuo(id,nm);
      int x=service.fanhuics(id,nm);
        return x;

    }


    @RequestMapping("/chasuoyou")
    public List<Red>chasuoyou(){
        List<Red>list=service.searchsuoyou();
        return list;
    }

    @RequestMapping("shanchu")
    public int shanchu(@RequestParam("id")int id){
        service.deletehb(id);
        return 1;
    }

    @RequestMapping("xinzeng")
    public int xinzeng(
            @RequestParam("users")String users,
            @RequestParam("preferentialway")String preferentialway,
            @RequestParam("parvalue")String parvalue,
            @RequestParam("threshold")String threshold,
            @RequestParam("totalissued")String totalissued
    ){
service.tianjiahb(users, preferentialway, parvalue, threshold, totalissued);
return 1;
    }

    @RequestMapping("/update")
    public int xiugai(
            @RequestParam("id")int id,
            @RequestParam("preferentialway")int preferentialway,
            @RequestParam("parvalue")int parvalue,
            @RequestParam("threshold")int threshold,
            @RequestParam("totalissued")int totalissued
    ){
        service.updatehb(id, preferentialway, parvalue, threshold, totalissued);
        return 1;
    }
    @RequestMapping("/yhjxiu")
    public int yhjxiu(  @RequestParam("id")String id,
                        @RequestParam("juan")String juan){
        service.juan(id,juan);
        return 1;
    }

    @RequestMapping("/addorder")
    public void addorder(Orders orders){

        Mingxi mingxi = new Mingxi();
        mingxi.setUserid(orders.getUserid());
        mingxi.setCommodity_name(orders.getCommodity_name());
        mingxi.setCommodity_picture(orders.getComitypicture());
        mingxi.setAttribute(orders.getSpecifications());
        mingxi.setJifen(orders.getJifen());



        userService.update_member_existing_integral(orders.getUserid(),"-"+orders.getJifen(),mingxi);
            orderService.insertorder(orders.getAddressid(), orders.getUserid(), orders.getSpid(), orders.getOrdernumber(), orders.getPayway(), orders.getComitydescription(),
                    orders.getComityprices(), orders.getComitynumber(), orders.getComitypicture(), orders.getSettlementprice(),
                    orders.getFreight(), orders.getActualpayment(), orders.getPreferentialinformation(), orders.getSpecifications()
            );



    }

    @RequestMapping("showaddress")
    public Mall_Data showaddress(@RequestParam("user_id") String user_id){
        System.out.println(11111);
        List<Address> addresses = service.showaddress(user_id);
        if (addresses.size()>0){
            Mall_Data mall_data = new Mall_Data();
            mall_data.setcode(1);
            mall_data.seterror("查询地址成功");
            mall_data.setdata(addresses);
            return mall_data;
        }
        Mall_Data mall_data = new Mall_Data();
        mall_data.setcode(0);
        mall_data.seterror("查询地址失败");
        mall_data.setdata("");
        return mall_data;
    }

}
